package org.fly.service.impl;

import org.fly.bean.ProductAttribute;
import org.fly.bean.query.ProductAttributeQuery;
import org.fly.dao.ProductAttributeDao;
import org.fly.service.ProductAttributeService;
import org.fly.utils.UUIDFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.fly.bean.common.BusinessException;
import java.util.List;

/**
* Created by autoCode on 2018-03-07 08:26:12.
*/
@Service
public class ProductAttributeServiceImpl implements ProductAttributeService {

    @Autowired
    ProductAttributeDao productAttributeDao;

    @Override
    public List<ProductAttribute> list(ProductAttributeQuery query) {
        return productAttributeDao.list(query);
    }

    @Override
    public long count(ProductAttributeQuery query) {
        return productAttributeDao.count(query);
    }

    @Override
    public ProductAttribute findById(String id) {
        return productAttributeDao.findById(id);
    }

    @Override
    public void save(ProductAttribute bean)  throws BusinessException {

    if(StringUtils.isNotBlank(bean.getId())){
         productAttributeDao.update(bean);
    }else {
        bean.setId(UUIDFactory.random());
        bean.setCreateTime(System.currentTimeMillis());
        productAttributeDao.insert(bean);
    }
    }

    @Override
    public void delete(String id) {
        productAttributeDao.delete(id);
    }
}
